package dataset.generation;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Iterator;

import org.mitre.jawb.io.SgmlDocument;
import org.mitre.jawb.io.SgmlElement;

public class IdValidator {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws FileNotFoundException 
	 */
	public static void main(String[] args) throws FileNotFoundException, IOException {
		
		String folderName = "/home/pjbarrio/Dataset/NaturalDisaster/RelatedData/xml/txt/";

		File folder = new File(folderName);
		
		File[] files = folder.listFiles();
		
		String[] tags = {"atLocation","locationOf"};
		
		for (File file : files) {
			
			if (file.getName().endsWith(".txt"))
				if (!valid(file,tags)){
					System.out.println("FILE WITH INCOMPLETE IDS: " + file.getName());
				}
			
		}
		
	}

	private static boolean valid(File file, String[] tags) throws FileNotFoundException, IOException {
		
		SgmlDocument sgmlDocument = new SgmlDocument(new FileReader(file));
		
		for (Iterator<SgmlElement> iterator = sgmlDocument.iterator(); iterator.hasNext();) {
			SgmlElement element = (SgmlElement) iterator.next();
			
			for (String string : tags) {
				
				if (element.getGid().equals(string)){
					
					String aux = element.getAttribute("id");
					
					if (aux.equals("")){
						
						return false;
					
					}
				}
				
			}
			
		}
		
		return true;
		
	}

}
